package com.shzu.jwc.ty.service;

import java.util.List;

import com.shzu.jwc.ty.bean.PeTest;
import com.shzu.jwc.ty.bean.PeTestExample;
import com.shzu.jwc.ty.common.Page;
import com.shzu.jwc.ty.dao.PeTestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shzu.jwc.ty.common.Semester;

@Service
public class PeTestservice {
	
	@Autowired
	PeTestMapper mapper;
	
	@Autowired
	SystemYearservice systemYearservice;

	public List<PeTest> getpetest()
	{
		Integer systemYearId=systemYearservice.getoneyearby(Semester.getnow());
		PeTestExample example=new PeTestExample();
		PeTestExample.Criteria criteria=example.createCriteria();
		criteria.andSystemYearIdEqualTo(systemYearId);
		criteria.andPeTestStateEqualTo(0);
		return mapper.selectByExample(example);
	}

	public List<PeTest> getpetestpage(Page page){
		return mapper.getpetest(0,systemYearservice.getoneyearby(Semester.getnow()),page.getStartPos(),page.getPageSize());
	}

	public Integer countpetestpage(){
		return (int)mapper.countpetest(0,systemYearservice.getoneyearby(Semester.getnow()));
	}

	public Integer countselectpetestpage(Integer systemYearId){
		return (int)mapper.countpetest(0,systemYearId);
	}

	public Integer insertpetest(PeTest peTest)
	{
		Integer systemYearId=systemYearservice.getoneyearby(Semester.getnow());
		peTest.setSystemYearId(systemYearId);
		peTest.setPeTestState(0);
		return mapper.insertSelective(peTest);
		
	}
	
	public PeTest getone(Integer peTestId)
	{
		return mapper.selectByPrimaryKey(peTestId);
	}
	
	public Integer delete(Integer peTestId)
	{
		PeTest peTest=new PeTest();
		peTest.setPeTestId(peTestId);
		peTest.setPeTestState(3);
		return mapper.updateByPrimaryKeySelective(peTest);
	}
	
	public Integer update(PeTest peTest)
	{
		return mapper.updateByPrimaryKeySelective(peTest);
	}
	
	public List<PeTest> search(String peTestName)
	{
		PeTestExample example=new PeTestExample();
		PeTestExample.Criteria criteria=example.createCriteria();
		criteria.andPeTestStateEqualTo(0);
		criteria.andPeTestNameLike("%"+peTestName+"%");
		return mapper.selectByExample(example);
	}

	public List<PeTest> bydatesearch(Integer systemYearId,Page page)
	{
//		PeTestExample example=new PeTestExample();
//		PeTestExample.Criteria criteria=example.createCriteria();
//		criteria.andSystemYearIdEqualTo(systemYearId);
//		criteria.andPeTestStateEqualTo(0);
		return mapper.getpetest(0,systemYearId,page.getStartPos(),page.getPageSize());
	}

	public Integer copyone(Integer peTestId){
		PeTest peTest=mapper.selectByPrimaryKey(peTestId);
		peTest.setPeTestId(null);
		peTest.setPeTestAddTime(null);
		return mapper.insertSelective(peTest);
	}
}
